package com.yc.auction.dao.impl;

import java.io.IOException;

import org.apache.ibatis.session.SqlSession;

import com.yc.auction.dao.DBAccess;
import com.yc.auction.dao.IUsersDao;
import com.yc.auction.entity.Users;

public class UsersDaoImpl{
	private DBAccess db=new DBAccess();
	private SqlSession session;
	
	public int add(Users users) {
		int result=0;
		try {
			session=db.getSqlSession();
			IUsersDao userDao=session.getMapper(IUsersDao.class);
			result=userDao.add(users);
			session.commit();
		} catch (IOException e) {
			session.rollback();
			e.printStackTrace();
		} finally{
			if(session!=null){
				session.close();
			}
		}
		return result;
	}

	public Users login(Users users) {
		Users user=null;
		try {
			session=db.getSqlSession();
			IUsersDao userDao=session.getMapper(IUsersDao.class);
			user=userDao.login(users);
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if(session!=null){
				session.close();
			}
		}
		return user;
	}
}
